import {
  request
} from '../../utils/requestUtils';

import { userBehavior } from '../../behaviors/userBehavior'

import {
  formatTime, isMoreThanHours
} from '../../utils/util';

Page({
  behaviors: [userBehavior],
  data: {
    options:'',
    minHour: new Date().getHours,
    show: false, // 期望送达日期弹框
    deliveryTimeshow: false,// 期望送达时间点
    minDate: new Date().getTime(),
    currentDate: new Date().getTime(),
    form: {
      customerName: '',
      contact: '',
      payableAmount: '0',
      deliveryStr: '',//送达时间点
      remark: '',
      addrId: '',//地址id
      lines: [],//行信息
      deliveryDate: formatTime(new Date())
    },
    returnFlag:true,
    cancelFlag:true,
    addr: {
      id: '',
    }
  },
  onShow() {
    this.getOrderById(this.options.id)
  },

  onLoad(options) {

  },
  //获取订单信息
  async getOrderById(id) {
    const result = await request({
      url: `/bus/customer/order/${id}`,
      method: "GET",
    })
    if (result.data.code == 200) {
      // 下单时间超过12小时不让退货
      this.setData({
        form: result.data.data,
        returnFlag: isMoreThanHours(result.data.data.createTime,1000 * 60 * 60 * 10),
        cancelFlag:isMoreThanHours(result.data.data.createTime, 1000 * 60 * 60 * 1)
      })
    }
  },

  // 提交订单
  submitOrder() {
    console.log('测试')
    wx.navigateTo({
      url: '/pages/customer_return_detail/index?orderId='+this.data.form.id
    })
  },
   // 提交订单
   async cancelOrder() {
    const modalRes = await wx.showModal({
      content: '确定取消订单 ?'
    })
    if (modalRes.cancel) return
    const result = await request({
      url: `/bus/customer/order/cancel`,
      method: "POST",
      data: {
        id: this.data.form.id
      },
    })
    if (result.data.code == 200) {
      wx.navigateBack({
        delta: 1
      })
    }
  }
})
